package beans.io;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class NoteProxy
{
	public String request(String strRequest) throws Exception
	{
		StringBuffer buffer = new StringBuffer();
		String strMessage = "";
		String strURL = "";
		strURL = "http://10.9.2.162:9082/smserver/submitMessage";
		// strRequest=newString(strRequest.getBytes("ISO_8859_1"),"GBK");
		// strRequest = URLEncoder.encode(strRequest,"ISO_8859_1");

		strURL = strURL + "?" + strRequest;
		// writer.info("URL=" + strURL);
		InputStream inputStream = null;
		BufferedReader reader = null;
		URL url = null;
		HttpURLConnection connection = null;
		try
		{
			url = new URL(strURL);
			connection = (HttpURLConnection) url.openConnection();
			connection.setDoInput(true);
			connection.setDoOutput(true);
			// connection.setUseCaches(false);
			connection.setRequestMethod("GET");// connection.setRequestMethod("POST");

			connection.setRequestProperty("Content-type", "text/html;charset=GBK");
			connection.connect();
			inputStream = connection.getInputStream();
			reader = new BufferedReader(new InputStreamReader(inputStream));
			while ((strMessage = reader.readLine()) != null)
			{
				buffer.append(strMessage.trim());
				buffer.append("\r\n");
			}

			if (buffer.length() < 1)
				throw new Exception(" 交互失败！ ");
		}
		catch (Exception ex)
		{
			throw ex;
		}
		finally
		{
			if (reader != null)
				reader.close();
		}
		return buffer.toString();
	}
}
